<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教师表管理</title>
    <link rel="stylesheet" href="./styles.css">
    <script src="./common.js"></script>
</head>
<body>
    <div class="container">
        <h1>教师表管理</h1>
        <div id="tableContainer"></div>
        <button onclick="showAddForm()">添加教师</button>
        <div id="addForm" style="display: none;">
            <input type="text" id="name" placeholder="姓名">
            <input type="text" id="class" placeholder="管理班级">
            <input type="text" id="gender" placeholder="性别">
            <input type="number" id="age" placeholder="年龄">
            <input type="date" id="dob" placeholder="出生年日">
            <input type="number" id="teacherNo" placeholder="教师编号">
            <button onclick="addTeacher()">确认添加</button>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            loadTable('teachers');
        });

        function showAddForm() {
            document.getElementById('addForm').style.display = 'block';
        }

        async function addTeacher() {
            const data = {
                姓名: document.getElementById('name').value,
                管理班级: document.getElementById('class').value,
                性别: document.getElementById('gender').value,
                年龄: parseInt(document.getElementById('age').value),
                出生年日: document.getElementById('dob').value,
                教师编号: parseInt(document.getElementById('teacherNo').value)
            };
            const success = await addData('teachers', data);
            if (success) {
                alert('教师添加成功');
                window.location.reload();
            } else {
                alert('教师添加失败');
            }
        }
    </script>
</body>
</html>
